package com.btex.app.push;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;

import com.btex.app.LoginActivity;
import com.btex.app.RegistActivity;
import com.btex.app.TabsActivity;
import com.btex.app.TradeActivity;
import com.btex.app.tools.LogUtil;

import org.json.JSONException;
import org.json.JSONObject;

public class NotifyTool {
    String result = null;
    String msg_id;


    public NotifyTool() {
    }

    /**
     * 跳转某特定界面
     *
     * @param customContentString
     * @param context
     */
    public void toUi(Context context, String customContentString) {
        LogUtil.i("XiaomiMessageReceiver", "1......");
        if (!TextUtils.isEmpty(customContentString)) {
            JSONObject customJson = null;
            try {
                customJson = new JSONObject(customContentString);

                if (!customJson.isNull("scheme")) {
                    result = customJson.getString("scheme");
                    LogUtil.i("scheme", "result:" + result);
                }
                if (!customJson.isNull("msg_id")) {     //获取消息的ID并返回给服务端
                    this.msg_id = customJson.getString("msg_id");
                    LogUtil.i("msg_id", msg_id);
                }

            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        //weicaixun://user?id=4510

        Intent intent = new Intent();
        if (result != null && result.contains("toubi://trade/")) {      //交易页面
            String pair = result.replace("toubi://trade/", "");
            intent.setClass(context.getApplicationContext(), TradeActivity.class);
            intent.putExtra("pair", pair);
        } else if (result != null && result.contains("toubi://pub/user_regist")) {  //注册页面
            intent.setClass(context.getApplicationContext(), RegistActivity.class);

        } else if (result != null && result.contains("toubi://home/")) {       //用户中心
            intent.setClass(context.getApplicationContext(), TabsActivity.class);
        } else if (result != null && result.contains("toubi://pub/user_login")) {    //登录页面
            intent.setClass(context.getApplicationContext(), LoginActivity.class);
        }
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//	        	context.startActivity(intent);
//	        	PendingIntent resultPendingIntent = PendingIntent.getActivity(  
//		        		context, 0, intent,  
//		        		PendingIntent.FLAG_UPDATE_CURRENT);

        try {
//					resultPendingIntent.send();
            LogUtil.i("XiaomiMessageReceiver", "点击后跳转。。。");
            context.startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
